
/*-----------------------------------------------*
Name: Haqdarshak Pilot Intervention-Analysis (for Appendix)
Date Created: 30 July, 2018
Date Last Modified: 28 April, 2021
Created by: Aaron Berman and modified by Daniela Paz and Saumya Mathur on Nov.13/2020 
Uses Data: baseline data hh_data_treatment_b.dta and intervention data on
screening counts pilot_intervention_household_screening_counts.dta
Creates Data: Latex Table for Appendix
Description: Creates attrition table
*-------------------------------------------------*/


*..................................................
**Install user-written commands
foreach package in mdesc nmissing veracrypt {
     capture which `package'
	 if _rc==111 ssc install `package'
}
*..................................................
clear all
set more off
version 12.0
cap log close
pause off




//open log 
*cd "$logs"
*log using "analysis_table_appendix1.smcl", replace


*Appendix Table 1: Attrition Check

	//start with baseline households randomized to treatment 
	use "$pilot/hh_data_treatment_b", clear 
	//keep only treatment households 
	keep if treatment == 1

	//code characteristics 
	//disability
	egen num_disabled = rowtotal(disabled_*)
	gen any_disability_hh = (num_disabled > 0) if !missing(num_disabled)
	gen member_male_1 = (member_gender_1 == 1)
	keep household_id any_disability_hh enter_annual_income above_48000 caste* applied_for_govt_scheme member_male_1 treatment stratum 

	//merge with household-level app data on screenings 
	replace household_id = 810125 if household_id == 401185
	merge 1:1 household_id using "$pilot/pilot_intervention_household_screening_counts"

	//generate attrition variable 
	gen attrited = (_merge == 1)
	drop _merge 

	//generate stratum FE variable 
	tab stratum, gen(d_stratum_)

	//regressions:
	eststo clear 
	foreach depvar of varlist above_48000 any_disability_hh applied_for_govt_scheme {
		eststo: reg `depvar' attrited d_stratum_*, robust 
		summ `depvar' if attrited == 0
		estadd scalar control_mean `r(mean)'
	}

	//output to latex 
	cd "$Appe"

	#delimit ;
	esttab *
		using "Table_A7.tex", booktabs label se
		drop(_cons d_stratum_*)
		b(%12.3f)
		se(%12.3f)
		starlevels(* .10 ** .05 *** .01)
		mlabels("Annual Income $/geq$ Rs. 48,000" "HH Member Disabled" "Applied for Gov't. Scheme in Last 2 Yrs.")
		varlab(attrited "Attrited")
		scalars("control_mean Non-Attrited Mean")
		nonotes
		fragment
		r2
		replace;

	#delimit cr 



